<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>敏感词列表</title>
    <link rel="stylesheet" href="/static/public/layui/css/layui.css">
    <script type="text/javascript" src="/static/public/layui/layui.js"></script>
</head>
<body style="padding: 15px">
<div>
    <button class="layui-btn" onclick="add()">添加</button>
</div>

<table class="layui-table">
    @csrf
    <thead>
    <tr>
        <th>ID</th>
        <th>名称</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    @foreach($cate_sw as $sw)
        <tr>
            <td>{{ $sw['id'] }}</td>
            <td>{{ $sw['name'] }}</td>

            <td>
                <button class="layui-btn layui-btn-xs" onclick="add({{ $sw['id'] }})">编辑</button>
                <button class="layui-btn layui-btn-danger layui-btn-xs" onclick="del({{ $sw['id'] }})">删除</button>
            </td>
        </tr>
    @endforeach

    </tbody>
</table>
<div id="pages"></div>
<script>
    layui.use(['layer','laypage'], function(){
        layer = layui.layer;
        $ = layui.jquery;
        laypage = layui.laypage;
        //分页参数
        laypage.render({
            elem: 'pages' //注意，这里的 test1 是 ID，不用加 # 号
            ,limit: {{ $pageSize }}
            ,count: {{ $total }} //数据总数，从服务端得到
            ,curr: {{ $page }}
            ,layout:['prev','page','next','skip','count']
            ,jump: function(obj, first){
                console.log(obj.curr); //得到当前页，以便向服务端请求对应页的数据。
                //首次不执行
                if(!first){
                    window.location.href = '?page='+obj.curr;
                }
            }
        });

    });
    //添加文章或修改文章
    function add(mid) {
        layer.open({
            type: 2,
            title: mid>0?'编辑敏感词':'添加敏感词',
            shadeClose: true,
            shade: 0.8,
            area: ['800px', '90%'],
            content: '/admin/sensitive/sw_add?mid='+mid
        });
    }

    //删除文章
    function del(mid) {
        layer.confirm('确定要删除吗？', {
            icon:3,
            btn: ['删除','取消'] //按钮
        }, function(){
            var _token = $('input[name="_token"]').val();
            $.post('/admin/sensitive/del_sw',{mid:mid,_token:_token},function (res) {
                if (res.code>0){
                    return layer.alert(res.msg,{icon:2});
                }
                layer.msg(res.msg);
                setTimeout(function () {
                    window.location.reload();

                },1000);
            },'json');
        });

    }

</script>
</body>
</html>
